﻿<UserControl x:Class="Locator.Silverlight.Client.ManageStoresControl"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           xmlns:converters="clr-namespace:Locator.Silverlight.Client.Converters"
           xmlns:map="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
    mc:Ignorable="d"
    DataContext="{Binding ManageStores, Source={StaticResource Locator}}" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" xmlns:my="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl.Common">
    <UserControl.Resources>
        <DataTemplate x:Key="PersonalLocationTemplate">
            <TextBlock Text="{Binding Description}"/>
        </DataTemplate>
        <DataTemplate x:Key="PushPinTemplate">
            <map:Pushpin map:Location="{Binding Store.Location}">
                <TextBlock Foreground="Black" FontSize="10" TextAlignment="Center" Text="{Binding Index}"/>
            </map:Pushpin>
        </DataTemplate>
        <converters:AddButtonStateConverter x:Key="AddButtonStateConverter"/>
        <converters:AddButtonContentConverter x:Key="AddButtonContentConverter"/>
        <DataTemplate x:Name="StoreTemplate">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Address}" Width="350" VerticalAlignment="Center" />
                <Button Content="Remove" Width="55" Command="{Binding ManageStores.RemoveStoreCommand, Source={StaticResource Locator}}" CommandParameter="{Binding}"/>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Name="NewStoreTemplate">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Index}" Width="30" VerticalAlignment="Center" MouseLeftButtonUp="TextBlock_MouseLeftButtonUp" />
                <TextBlock Text="{Binding Store.Address}" Width="240" VerticalAlignment="Center" MouseLeftButtonUp="TextBlock_MouseLeftButtonUp" />
                <Button Content="{Binding UsedByUser, Converter={StaticResource AddButtonContentConverter}}" IsEnabled="{Binding UsedByUser, Converter={StaticResource AddButtonStateConverter}}" Width="55" Command="{Binding ManageStores.AddStoreCommand, Source={StaticResource Locator}}" CommandParameter="{Binding}"/>
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>
        <Grid x:Name="LayoutRoot" Background="White">
        <toolkit:Accordion Height="200" HorizontalAlignment="Left" Margin="12,12,0,0" Name="accordionSearch" VerticalAlignment="Top" Width="289" SelectionMode="One" SelectionSequence="CollapseBeforeExpand">
            <toolkit:AccordionItem Header="Search By Postal Code">
                <StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock VerticalAlignment="Center" Width="100">Postal Code:</TextBlock>
                        <TextBox Name="PostalCodeTextBox" Width="75" Margin="12,0,0,0" VerticalAlignment="Center" Text="{Binding PostalCode, Mode=TwoWay}"></TextBox>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Search Distance:" Width="100" />
                        <ComboBox Name="ComboBoxSearchRadius" Margin="12,0,0,0" Width="75" ItemsSource="{Binding SearchRadiusItems}" SelectedItem="{Binding SearchRadius, Mode=TwoWay}" />
                    </StackPanel>
                    <Button Name="SearchPostalCodeButton" Content="Search" Width="75" Margin="0,0,0,0" Command="{Binding FindStoresByPostalCodeCommand}"></Button>
                </StackPanel>
            </toolkit:AccordionItem>
            <toolkit:AccordionItem Header="Search By City">
                <StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Width="75" VerticalAlignment="Center">Enter City:</TextBlock>
                        <sdk:AutoCompleteBox Name="autoCompleteBoxCity" Width="100" Margin="12,0,0,0" ItemsSource="{Binding AllCities}" ValueMemberPath="Name" MinimumPrefixLength="2" FilterMode="StartsWith">
                            <sdk:AutoCompleteBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Name}"/>
                                </DataTemplate>
                            </sdk:AutoCompleteBox.ItemTemplate>
                        </sdk:AutoCompleteBox>
                        <!--<TextBox Name="CityTextBox" Width="100" Margin="12,0,0,0" VerticalAlignment="Center" Text="{Binding CityNameToSearch, Mode=TwoWay}"></TextBox>-->
                        <Button Name="CityTextButton" Content="Search" Width="75" Margin="12,0,0,0" Command="{Binding FindStoresCommand}" CommandParameter="{Binding ElementName=autoCompleteBoxCity, Path=Text}"></Button>
                    </StackPanel>
                    <TextBlock TextAlignment="Center" Text="Or"/>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Width="75">Select City:</TextBlock>
                        <ComboBox Name="comboBoxCity" Width="100" Margin="12,0,0,0" ItemsSource="{Binding AllCities}" DisplayMemberPath="Name"></ComboBox>
                        <Button Name="CityComboButton" Content="Search" Width="75" Margin="12,0,0,0" Command="{Binding FindStoresCommand}" CommandParameter="{Binding ElementName=comboBoxCity, Path=SelectedItem.Name}"></Button>
                    </StackPanel>
                </StackPanel>
            </toolkit:AccordionItem>
            <toolkit:AccordionItem Header="Search By Personal Location">
                <StackPanel Width="289">
                    <ListBox Height="75" Width="200" Name="ListBoxPersonalLocations" HorizontalAlignment="Center" ItemsSource="{Binding PersonalLocations}" SelectedItem="{Binding CurrentPersonlLocation, Mode=TwoWay}" ItemTemplate="{StaticResource PersonalLocationTemplate}" />
                    <StackPanel Orientation="Horizontal" >
                        <TextBlock>Search Radius:</TextBlock>
                        <ComboBox Name="ComboBoxPersonalLocationRadius" Width="75" ItemsSource="{Binding SearchRadiusItems}" SelectedItem="{Binding SearchPersonalLocationRadius, Mode=TwoWay}" />
                    </StackPanel>
                    <Button Content="Search" Name="ButtonSearchByPersonalLocation" Width="50" Command="{Binding FindStoresByPersonalLocationCommand}" CommandParameter="{Binding ElementName=ListBoxPersonalLocations, Path=SelectedItem}" />
                </StackPanel>
            </toolkit:AccordionItem>
        </toolkit:Accordion>
        <ListBox Height="199" HorizontalAlignment="Left" Margin="12,327,0,0" Name="listBoxCurrentStores" VerticalAlignment="Top" Width="437" ItemsSource="{Binding UserStores}" ItemTemplate="{StaticResource StoreTemplate}"/>
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="14,298,0,0" Name="textBlockYourStores" Text="Your Stores" VerticalAlignment="Top" />
        <ListBox Height="221" HorizontalAlignment="Left" Margin="307,36,0,0" Name="listBoxResults" VerticalAlignment="Top" Width="353" ItemsSource="{Binding SearchResults}" ItemTemplate="{StaticResource NewStoreTemplate}"/>
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="307,12,0,0" Name="textBlockSearchResults" Text="Search Results" VerticalAlignment="Top" />
        <map:Map Width="300" Height="300" Margin="666,12,12,214" CopyrightVisibility="Collapsed" Center="43.6,-79.5,0" ZoomLevel="8" Culture="en-CA" CredentialsProvider="{StaticResource MyCredentials}" Name="mapResults">
            <map:MapItemsControl x:Name="MapSearchResults" ItemTemplate="{StaticResource PushPinTemplate}" ItemsSource="{Binding SearchResults}"/>
        </map:Map>

    </Grid>
</UserControl>
